import java.util.InputMismatchException;
import java.util.Scanner;

class Person{
    public String name;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

public class Test {
    //如果catch之间存在父子关系，则子在前，父在后
    public static void main8(String[] args) {
        try {
            int[] arr = null;
            System.out.println(arr[0]);
        } catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }


    //最后出finally里面的值
    public static int funtion() {
        Scanner scanner = new Scanner(System.in);
        try {
            int a = scanner.nextInt();
            return a;
        } catch (InputMismatchException e){
            e.printStackTrace();
        } finally {
            return 99;
        }
    }

    public static void main7(String[] args) {
        System.out.println(funtion());
    }


    //try - catch -finally
    public static void main6(String[] args){
        try {
            int[] arr = {1,2,3,4,5};
            System.out.println(arr[6]);
        }catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("超出范围");
        }catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("空指针");
        }finally {
            System.out.println("hhhhhh");
        }
        System.out.println("bbbbbb");
    }


    //catch可以合并
    public static void main5(String [] args) {
        try {
            int[] arr = null;
            System.out.println(arr[0]);
        }catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
            e.printStackTrace();
        }
        System.out.println("程序继续运行");
    }


    //try - catch
    public static void main4(String[] args) {
        try {
            int[] arr = {1,2,3};
            System.out.println(arr[5]);
            System.out.println("haha");
        }catch(ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("超出范围");
        }catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("空指针");
        }
        System.out.println("程序继续运行");
    }


    //throw
    public static void main3(String[] args) {
        int[] array = null;
        if (array == null) {
            throw new NullPointerException("空指针");
        }
        System.out.println("hhhh");
    }


    //throws
    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person = new Person();
        Person person1 = (Person) person.clone();
    }


    public static void main1(String[] args) {
        System.out.println(10/0);
        System.out.println("继续执行");
    }
}

